from strategy.core.Stg import Stg
import talib.abstract as ta
import math
import pandas as pd


class DownLimit(Stg):
    """
    跌停板战法: 跌停买入, 第二天卖出
    """

    def initial(self):
        return

    def signal(self, index):
        priceDetial = self.getPriceDetail()

        # 检查昨日是否买入, 如果买入今日卖出
        if index > 0:
            preDate = str(self.getPriceDetail(-1)['trade_date'])
            if preDate in self.signals and self.signals[preDate] == 1:
                return -1
        # 检查跌停买入
        if priceDetial['pct_chg'] < -9.9:
            return 1

        return 0
